package com.iyao_app.mvp.storydetail;

import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CoordinatorLayout;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.backends.pipeline.PipelineDraweeController;
import com.facebook.drawee.view.SimpleDraweeView;
import com.facebook.imagepipeline.common.ResizeOptions;
import com.facebook.imagepipeline.request.ImageRequest;
import com.facebook.imagepipeline.request.ImageRequestBuilder;
import com.iyao_app.R;
import com.iyao_app.adapter.CommentAdapter;
import com.iyao_app.adapter.PictureAdapter;
import com.iyao_app.base.BaseActivityWithHead;
import com.iyao_app.entry.CommentData;
import com.iyao_app.entry.CommentList;
import com.iyao_app.entry.DemoData;
import com.iyao_app.entry.PageInfo;
import com.iyao_app.entry.PreviewData;
import com.iyao_app.entry.ResultModel;
import com.iyao_app.entry.ShareData;
import com.iyao_app.entry.StoryDetail;
import com.iyao_app.entry.User;
import com.iyao_app.http.NetCallBack;
import com.iyao_app.http.NetUtils;
import com.iyao_app.mvp.other.OtherHomeActivity;
import com.iyao_app.mvp.preview.ImageViewPagerActivity;
import com.iyao_app.util.Contants;
import com.iyao_app.util.CountUtils;
import com.iyao_app.util.DbUtil;
import com.iyao_app.util.FrescoImageLoader;
import com.iyao_app.util.MessageEvent;
import com.iyao_app.util.ResourcesUtils;
import com.iyao_app.util.RxHeartLayout_;
import com.iyao_app.util.TimeFormat;
import com.iyao_app.util.ToastUtil;
import com.iyaowoqu.base_library.util.AppUtil;
import com.iyaowoqu.base_library.util.KeyboardUtils;
import com.iyaowoqu.base_library.util.LogUtil;
import com.iyaowoqu.base_library.util.PopupWindowUtils;
import com.iyaowoqu.base_library.util.ScreenUtils;
import com.iyaowoqu.base_library.util.Utils;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadmoreListener;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;
import com.youth.banner.listener.OnBannerListener;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.github.rockerhieu.emojicon.EmojiconEditText;

/**
 * 作者 :  胡家兵
 * 时间 :  2017/11/11.
 */

public class StoryDetailActivity extends BaseActivityWithHead implements OnLoadmoreListener {

    @BindView(R.id.x_recyclerView)
    RecyclerView xRecyclerView;
    @BindView(R.id.sdv_head)
    SimpleDraweeView mSdvHead;
    @BindView(R.id.tv_name)
    TextView mTvName;
    @BindView(R.id.tv_time)
    TextView mTvTime;
    @BindView(R.id.tv_guanzhu)
    TextView mTvGuanzhu;
    //    @BindView(R.id.sdv_photo)
//    SimpleDraweeView mSdvPhoto;
    @BindView(R.id.rv_horizontal)
    RecyclerView mRvHorizontal;
    @BindView(R.id.tv_location)
    TextView mTvLocation;
    @BindView(R.id.tv_content)
    TextView mTvContent;
    @BindView(R.id.tv_like)
    TextView mTvLike;
    @BindView(R.id.tv_comment)
    TextView mTvComment;
    @BindView(R.id.tv_zhuanfa)
    TextView mTvZhuanfa;
    @BindView(R.id.appBarLayout)
    AppBarLayout mAppBarLayout;
    @BindView(R.id.nest_scroll)
    NestedScrollView mNestScroll;
    @BindView(R.id.coordinatorLayout)
    CoordinatorLayout mCoordinatorLayout;
    @BindView(R.id.toolbar)
    Toolbar mToolbar;
    @BindView(R.id.banner)
    Banner banner;
    @BindView(R.id.et_input)
    EmojiconEditText mEtInput;
    @BindView(R.id.smart_refresh)
    SmartRefreshLayout mSmartRefresh;
    @BindView(R.id.heart_layout)
    RxHeartLayout_ rxHeartLayout;
    @BindView(R.id.iv_like)
    ImageView mIvLike;


    private PictureAdapter pictureAdapter;
    private StaggeredGridLayoutManager staggeredGridLayoutManager;
    private int eventId;
    private StoryDetail storyDetail;
    private int page = 1;
    private final int pageSize = 10;
    private CommentAdapter adapter;
    private View rl_no_comment;
    private User user;
    private int count = 0;
    private int position = 0;
    private int i;
    private ShareData shareUrl;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_story_detail);
        ButterKnife.bind(this);
        init();
    }

    private void init() {
        eventId = getIntent().getIntExtra(Contants.TYPE, 0);
        storyDetail = (StoryDetail) getIntent().getSerializableExtra(Contants.CLASS_TYPE);
        position = storyDetail.position;
        user = DbUtil.getUser();
        LogUtil.e("=====" + eventId);
        LogUtil.e("==故事详情==" + eventId);
        setTitleTV("故事详情");
        xRecyclerView.setNestedScrollingEnabled(false);

        mRvHorizontal.setFocusable(false);
        banner.setFocusable(false);

        LinearLayoutManager manager = new LinearLayoutManager(this);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        xRecyclerView.setLayoutManager(manager);

        adapter = new CommentAdapter(null);
        xRecyclerView.setAdapter(adapter);
        View headView = LayoutInflater.from(this).inflate(R.layout.story_detail_head, null);
        rl_no_comment = headView.findViewById(R.id.rl_no_comment);
        headView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        adapter.addHeaderView(headView);

        mSmartRefresh.setOnLoadmoreListener(this);
        mSmartRefresh.setEnableRefresh(false);
        mSmartRefresh.setEnableLoadmore(true);
        int size = ScreenUtils.getScreenWidth() - AppUtil.dp2px(this, 50);
        banner.setLayoutParams(new RelativeLayout.LayoutParams(size, size));
        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) rxHeartLayout.getLayoutParams();
        layoutParams.height = size + 100;
        rxHeartLayout.setLayoutParams(layoutParams);
        staggeredGridLayoutManager = new StaggeredGridLayoutManager(9, StaggeredGridLayoutManager.VERTICAL);


        pictureAdapter = new PictureAdapter(this, null);
        mRvHorizontal.setAdapter(pictureAdapter);
        mRvHorizontal.setLayoutManager(staggeredGridLayoutManager);

        banner.setImageLoader(new FrescoImageLoader());
        //设置banner样式
        banner.setBannerStyle(BannerConfig.NOT_INDICATOR);
        //设置banner动画效果
        banner.setBannerAnimation(Transformer.ZoomOutSlide);
        banner.isAutoPlay(false);

        pictureAdapter.setOnPictureSelectListener(new PictureAdapter.PictureSelectListener() {
            @Override
            public void onSelect(int position) {
                LogUtil.e("====" + position);
                banner.setCurrentItem(position);
            }
        });
        banner.setOnBannerListener(new OnBannerListener() {
            @Override
            public void OnBannerClick(int position) {
                LogUtil.e("=====" + position);

                List<String> eventFileUrlList = storyDetail.eventFileUrlList;
                PreviewData previewData = new PreviewData();
                previewData.image = eventFileUrlList;
                previewData.position = position;
                Intent intent = new Intent(StoryDetailActivity.this, ImageViewPagerActivity.class);
                intent.putExtra(Contants.CLASS_TYPE, previewData);
                startActivity(intent);
            }
        });
        banner.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {

                for (int i = 0; i < pictureAdapter.data.size(); i++) {
                    DemoData demoData = pictureAdapter.data.get(i);
                    if (position == i) {
                        demoData.setSelect(true);
                    } else {
                        demoData.setSelect(false);
                    }
                    pictureAdapter.notifyDataSetChanged();
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        initData();
        getData();
        mEtInput.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId,
                                          KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_SEND || (event != null && event.getKeyCode() == KeyEvent.KEYCODE_SEARCH)) {
                    KeyboardUtils.hideSoftInput(StoryDetailActivity.this);
                    if (TextUtils.isEmpty(mEtInput.getText().toString().trim())) {
                        Toast.makeText(StoryDetailActivity.this, "请输入评论内容", Toast.LENGTH_SHORT).show();
                    } else {
                        comment();
                    }
                    return true;
                }

                return false;
            }
        });
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                CommentData item = (CommentData) adapter.getItem(position);
                Intent intent = new Intent(StoryDetailActivity.this, OtherHomeActivity.class);
                intent.putExtra(Contants.TYPE, String.valueOf(item.userId));
                startActivity(intent);
            }
        });
    }

    private void share() {
        NetUtils.getInstance().share(user.id, "2", eventId + "", null, new NetCallBack() {
            @Override
            public void onSuccess(String message, int code, String response, ResultModel model) {
                if (code == Contants.SUCCESS_CODE) {
                    if (model != null) {
                        shareUrl = model.getModel();
                        if (shareUrl != null) {
                            final PopupWindowUtils popupWindowUtils = PopupWindowUtils.getInstance();
                            popupWindowUtils.attachActivity(StoryDetailActivity.this, R.layout.pop_share, mCoordinatorLayout)
                                    .wiewSize(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)
                                    .location(Gravity.BOTTOM, 0, Utils.getBottomStatusHeight(StoryDetailActivity.this))
                                    .focuseAble(true)
                                    .Animation(PopupWindowUtils.ANIMATION_BOTTOM)
                                    .setPopupWindowItemViewClickListener(new PopupWindowUtils.SetonPopWindowItemViewClickListenter() {
                                        @Override
                                        public void onPopWindowItemViewClickListener(int id) {

                                            boolean install = UMShareAPI.get(StoryDetailActivity.this).isInstall(StoryDetailActivity.this, SHARE_MEDIA.WEIXIN);
                                            if (install) {
                                                UMImage umImage = new UMImage(StoryDetailActivity.this, R.mipmap.logo);
                                                UMWeb web = new UMWeb(shareUrl.shareUrl);
                                                web.setTitle("“哎吆我去”邀您来玩");//标题
                                                web.setThumb(umImage);  //缩略图
                                                web.setDescription("一款好玩儿的交友平台，给你不一样的赶脚！");//描述
                                                switch (id) {
                                                    case R.id.tv_friend:

                                                        new ShareAction(StoryDetailActivity.this)
                                                                .withMedia(web)
                                                                .setPlatform(SHARE_MEDIA.WEIXIN_CIRCLE)
                                                                .share();

                                                        break;
                                                    case R.id.tv_weixin:
                                                        new ShareAction(StoryDetailActivity.this)
                                                                .withMedia(web)
                                                                .setCallback(umShareListener)
                                                                .setPlatform(SHARE_MEDIA.WEIXIN)
                                                                .share();
                                                        break;
                                                }
                                            } else {
                                                Toast.makeText(StoryDetailActivity.this, "请先安装微信客户端", Toast.LENGTH_SHORT).show();
                                            }
                                        }
                                    }, R.id.tv_friend, R.id.tv_weixin)
                                    .show();
                        }
                    }


                }
            }

            @Override
            public void onFail(String message, int code) {

            }
        }, ShareData.class);

    }


    private UMShareListener umShareListener = new UMShareListener() {
        @Override
        public void onStart(SHARE_MEDIA share_media) {

        }

        @Override
        public void onResult(SHARE_MEDIA platform) {
            LogUtil.e("plat" + "============" + "platform" + platform);
            Toast.makeText(StoryDetailActivity.this, " 分享成功啦", Toast.LENGTH_SHORT).show();
            shareUpdate();
        }

        @Override
        public void onError(SHARE_MEDIA platform, Throwable t) {
            Toast.makeText(StoryDetailActivity.this, " 分享失败啦", Toast.LENGTH_SHORT).show();
            if (t != null) {
                LogUtil.e("throw" + "============" + "throw:" + t.getMessage());
            }
        }

        @Override
        public void onCancel(SHARE_MEDIA platform) {
            Toast.makeText(StoryDetailActivity.this, " 分享取消了", Toast.LENGTH_SHORT).show();
        }
    };

    private void shareUpdate() {
        NetUtils.getInstance().shareUpdate(shareUrl.shareId, new NetCallBack() {
            @Override
            public void onSuccess(String message, int code, String response, ResultModel model) {

            }

            @Override
            public void onFail(String message, int code) {

            }
        }, null);
    }

    private void initData() {

        List<String> images = storyDetail.eventFileUrlList;
        List<DemoData> data = new ArrayList();
        if (images != null && images.size() > 0) {
            for (int i = 0; i < images.size(); i++) {
                if (i == 0) {
                    data.add(new DemoData(true, images.get(i)));
                } else {
                    data.add(new DemoData(false, images.get(i)));
                }
            }
            banner.update(images);
            banner.start();
            pictureAdapter.clear();
            pictureAdapter.append(data);
        }

        try {
            String avatarUrl = storyDetail.avatarUrl;
            if (avatarUrl != null) {
                Uri uri = Uri.parse(avatarUrl);
                ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri)
                        .setResizeOptions(new ResizeOptions(80, 80))
                        .build();
                PipelineDraweeController controller = (PipelineDraweeController) Fresco.newDraweeControllerBuilder()
                        .setOldController(mSdvHead.getController())
                        .setImageRequest(request)
                        .build();
                mSdvHead.setController(controller);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        mTvName.setText(storyDetail.nickname);
        String s = TimeFormat.getTime(storyDetail.createTime);
        mTvTime.setText(s);
        mTvLocation.setText(storyDetail.sceneName);
        String goodCount = storyDetail.goodCount;

        if (!TextUtils.isEmpty(goodCount)) {
            count = Integer.parseInt(goodCount);
        }
        mTvLike.setText(CountUtils.getCount(goodCount));
        mTvComment.setText(CountUtils.getCount(storyDetail.commentCount));
        mTvContent.setText(storyDetail.eventDesc);
        mTvZhuanfa.setText("");
        if (!storyDetail.goodVote) {
            mTvLike.setTextColor(ResourcesUtils.getColor(R.color.app_orange_ff773d));
            mIvLike.setImageResource(R.mipmap.btn_wuxianxihuan_lager);
        }

        if (user.id.equals(String.valueOf(storyDetail.userId))) {
            mTvGuanzhu.setVisibility(View.GONE);
        } else {
            mTvGuanzhu.setVisibility(View.VISIBLE);
            showGuanzhu();
        }
    }

    private void showGuanzhu() {
        switch (storyDetail.friendShip) {
            case 1:
                mTvGuanzhu.setSelected(false);
                mTvGuanzhu.setText("已关注");
                break;
            case 4:
                mTvGuanzhu.setSelected(false);
                mTvGuanzhu.setText("已关注");
                break;
            default:
                mTvGuanzhu.setText("关注");
                mTvGuanzhu.setSelected(true);
                break;
        }
    }

    private void getData() {
        NetUtils.getInstance().getEventDetail(DbUtil.getUser().id, eventId, new NetCallBack() {
            @Override
            public void onSuccess(String message, int code, String response, ResultModel model) {
                if (code == Contants.SUCCESS_CODE) {
                    if (model != null) {
                        storyDetail = model.getModel();
                        if (storyDetail != null) {
                            initData();
                        }
                    }
                }
            }

            @Override
            public void onFail(String message, int code) {

            }
        }, StoryDetail.class);

        commentList(true);
    }

    private void commentList(final boolean isRefresh) {
        if (isRefresh) {
            page = 1;
        } else {
            page++;
        }
        NetUtils.getInstance().commentList(eventId, page, pageSize, new NetCallBack() {
            @Override
            public void onSuccess(String message, int code, String response, ResultModel model) {
                if (model != null && model.getModel() != null) {
                    CommentList commentList = model.getModel();
                    List<CommentData> list = commentList.list;
                    PageInfo pageInfo = commentList.pageInfo;
                    if (!isRefresh) {
                        mSmartRefresh.finishLoadmore();
                    }
                    if (pageInfo.pageTotal <= page) {
                        mSmartRefresh.finishLoadmoreWithNoMoreData();
                    }
                    if (list != null && list.size() > 0) {
                        rl_no_comment.setVisibility(View.GONE);
                        if (isRefresh) {
                            adapter.getData().clear();
                        }
                        adapter.addData(list);
                    } else {
                        if (isRefresh) {
                            rl_no_comment.setVisibility(View.VISIBLE);
                        }
                    }
                } else {
                    if (isRefresh)
                        rl_no_comment.setVisibility(View.VISIBLE);
                }
            }

            @Override
            public void onFail(String message, int code) {
                mSmartRefresh.finishLoadmore();
            }
        }, CommentList.class);
    }

    private void like() {
        NetUtils.getInstance().goodOrBad(eventId, user.id, new NetCallBack() {
            @Override
            public void onSuccess(String message, int code, String response, ResultModel model) {
                if (code == Contants.SUCCESS_CODE) {

                    count++;
                    storyDetail.goodCount = String.valueOf(count);
                    storyDetail.goodVote = false;
                    mTvLike.setText(storyDetail.goodCount);
                    mTvLike.setTextColor(ResourcesUtils.getColor(R.color.app_orange_ff773d));
                    mIvLike.setImageResource(R.mipmap.btn_wuxianxihuan_lager);
                    MessageEvent event = new MessageEvent(MessageEvent.UPDATE_STORY);
                    storyDetail.position = position;
                    event.setMessage(storyDetail);
                    EventBus.getDefault().post(event);
                }

            }

            @Override
            public void onFail(String message, int code) {

            }
        }, null);
//
    }

    private void comment() {
        NetUtils.getInstance().comment(user.id, eventId, mEtInput.getText().toString().trim(), new NetCallBack() {
            @Override
            public void onSuccess(String message, int code, String response, ResultModel model) {
                if (code == Contants.SUCCESS_CODE) {
                    Toast.makeText(StoryDetailActivity.this, "评论成功", Toast.LENGTH_SHORT).show();
                    mEtInput.setText("");
                    storyDetail.commentCount += 1;
                    mTvComment.setText(String.valueOf(storyDetail.commentCount));
                    getData();
                    MessageEvent event = new MessageEvent(MessageEvent.UPDATE_STORY);
                    storyDetail.position = position;
                    event.setMessage(storyDetail);
                    EventBus.getDefault().post(event);
                }
            }

            @Override
            public void onFail(String message, int code) {

            }
        }, null);
    }

    final int[] image = {R.mipmap.ic_a, R.mipmap.ic_b, R.mipmap.ic_c, R.mipmap.ic_d, R.mipmap.ic_e, R.mipmap.ic_f, R.mipmap.ic_g, R.mipmap.ic_h, R.mipmap.ic_i, R.mipmap.ic_j, R.mipmap.ic_k};

    private Random random = new Random();

    @OnClick({R.id.tv_guanzhu, R.id.tv_location, R.id.lin_like, R.id.tv_comment, R.id.tv_zhuanfa, R.id.sdv_head})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_guanzhu:
                if ("关注".equals(mTvGuanzhu.getText())) {
                    guanzhu();
                } else {
                    cancleFriend();
                }
                break;
            case R.id.tv_location:
                break;
            case R.id.lin_like:
                like();
//                rxHeartLayout.post(new Runnable() {
//                    @Override
//                    public void run() {
//                        int rgb = Color.rgb(random.nextInt(255), random.nextInt(255), random.nextInt(255));
//                        rxHeartLayout.addHeart(rgb);
//                    }
//                });
                i = random.nextInt(image.length);
                rxHeartLayout.post(new Runnable() {
                    @Override
                    public void run() {
                        int rgb = Color.rgb(random.nextInt(255), random.nextInt(255), random.nextInt(255));
                        rxHeartLayout.addHeart(rgb, image[i], image[i]);
                    }
                });
                break;
            case R.id.tv_comment:

                break;
            case R.id.tv_zhuanfa:

                share();
                break;
            case R.id.sdv_head:
                Intent intent = new Intent(StoryDetailActivity.this, OtherHomeActivity.class);
                intent.putExtra(Contants.TYPE, String.valueOf(storyDetail.userId));
                startActivity(intent);
                break;
        }
    }

    private void cancleFriend() {

        final PopupWindowUtils popupWindowUtils = PopupWindowUtils.getInstance();
        popupWindowUtils.attachActivity(StoryDetailActivity.this, R.layout.item_popupwindow, mCoordinatorLayout)
                .wiewSize(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)
                .location(Gravity.BOTTOM, 0, Utils.getBottomStatusHeight(this))
                .focuseAble(true)
                .Animation(PopupWindowUtils.ANIMATION_BOTTOM)
                .setPopupWindowItemViewClickListener(new PopupWindowUtils.SetonPopWindowItemViewClickListenter() {
                    @Override
                    public void onPopWindowItemViewClickListener(int id) {
                        switch (id) {
                            case R.id.pop_financial://确认
                                unfollowFriend();
                                popupWindowUtils.dissMissPopWindow();
                                break;
                            case R.id.pop_manage://取消
                                popupWindowUtils.dissMissPopWindow();
                                break;
                        }
                    }
                }, R.id.pop_financial, R.id.pop_manage)
                .show();
    }

    private void guanzhu() {
        String userId = String.valueOf(storyDetail.userId);
        NetUtils.getInstance().followFriend(userId, storyDetail.nickname, storyDetail.avatarUrl, storyDetail.sex, new NetCallBack() {
            @Override
            public void onSuccess(String message, final int code, String response, final ResultModel model) {
                ToastUtil.showToast(StoryDetailActivity.this, "关注成功");
                storyDetail.friendShip = 1;
                showGuanzhu();
            }

            @Override
            public void onFail(String message, int code) {

            }
        }, null);
    }

    private void unfollowFriend() {
        String userId = String.valueOf(storyDetail.userId);
        NetUtils.getInstance().unfollowFriend(userId, new NetCallBack() {
            @Override
            public void onSuccess(String message, final int code, String response, final ResultModel model) {
                if (code == Contants.SUCCESS_CODE) {
                    ToastUtil.showToast(StoryDetailActivity.this, "取消关注成功");
                    storyDetail.friendShip = -1;
                    showGuanzhu();
                }
            }

            @Override
            public void onFail(String message, int code) {

            }
        }, null);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);//完成回调
        LogUtil.e("========" + this.getClass().getSimpleName());
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        banner.releaseBanner();
        UMShareAPI.get(this).release();
    }

    @Override
    public void onLoadmore(RefreshLayout refreshlayout) {
        commentList(false);
    }
}
